<template>
	<view class="mainContent">
		<view class="header">			
			<view class="navigatorModular">
				<view class="classification">
					<div class="classifcation-a">
						<!-- :style="{'transform': 'translateX('+((currentIndex)*-40)+'px)'}" -->
						<text :class="currentIndex == index ? 'on' : 'classObject'" v-for="(item,index) in classifcationArr" @click="tabClick(index)" :key="index">{{item}} 
							<image src="@/static/img/healthStatus/dropDown.png" v-show="currentIndex == index"></image>
						</text>
					</div>
				</view>
				<image src="@/static/img/healthStatus/split1.png" class="split"></image>
				<image src="@/static/img/healthStatus/open.png" class="open" @click="bulletFrame = !bulletFrame"></image>
			</view>
		</view>

		<view class="listMular">
			<uni-swipe-action v-if="allData.length > 0" style="margin-top: 114upx;">
				<view class="box" v-for="(item,index) in allData" :key="index">
					<image src="@/static/img/monitor/healthStatus/number@2x.png" class="sn"></image>
					<uni-swipe-action-item :right-options="item.status!=3 ? options : []"  @click="bindClick(item)">
						<view class="top">
							<text class="assementNumber">{{item.status == 2 || item.status == 4 ? '评估编号' : item.sn}}</text>
							<text :class="item.status == 4 ?'dataTime1': 'dataTime'">{{item.status == 4?'未评估':item.fillFormDate}}</text>
						</view>
						<view class="bottom">
							<view class="nameBox">
								<text class="userName">{{item.userName}}</text>
								<image src="@/static/img/healthStatus/evaluate@2x.png" v-if="item.status != 4"></image>
								<text class="healthName"  v-if="item.status != 4">{{item.healthName}}</text>
							</view>
							<view class="buttonBox">	
								<view class="qsDetail" @click="detail(item)">详情</view>
								<view class="applyFor" v-if="item.status == 4" @click="creat(item)">申请评估</view>
								<view class="generating" v-else-if="item.status == 2">申请中</view>
								<view class="viewAssessment" v-else-if ="item.status == 3" @click="check(item)">查看报告</view>
							</view>
						</view>
					</uni-swipe-action-item>
				</view>
			</uni-swipe-action>
			
			<view class="noData" v-else>
				<image src="@/static/img/healthStatus/none.png"></image>
				<view>您还没有评估文件~</view>
			</view>
		</view>
		
		<view class="location">
			<image src="@/static/img/monitor/healthStatus/add@2x.png" @click="addQuestion"></image>
		</view>
		
		<!-- 自定义弹框 -->
		<view class="mask" v-if="bulletFrame"  @click="bulletFrame = false"></view>
		<view class="uniPop" v-if="bulletFrame">
			<view class="navigatorModular" v-for="(aitem,aindex) in classifcationArr" :key="aindex" @click="navigationClick(aindex)">
				<image src='@/static/img/healthStatus/lifeOn@2x.png' v-if="aindex == 0 && currentIndex == 0"></image>
				<image src='@/static/img/healthStatus/life@2x.png' v-else-if="aindex == 0"></image>
				<image src="@/static/img/healthStatus/examinationSelect@2x.png" v-if="aindex == 1 && currentIndex == 1"></image>
				<image src="@/static/img/healthStatus/examination@2x.png" v-else-if="aindex == 1"></image>
				<image src="@/static/img/healthStatus/heartOn@2x.png" v-if="aindex == 2 && currentIndex == 2"></image>
				<image src="@/static/img/healthStatus/heart@2x.png" v-else-if="aindex == 2"></image>
				<image src="@/static/img/healthStatus/accomplishmentOn@2x.png" v-if="aindex == 3 && currentIndex == 3"></image>
				<image src="@/static/img/healthStatus/accomplishment@2x.png" v-else-if="aindex == 3"></image>
				<image src="@/static/img/healthStatus/anxiousOn@2x.png" v-if="aindex == 4 && currentIndex == 4"></image>
				<image src="@/static/img/healthStatus/anxious@2x.png" v-else-if="aindex == 4"></image>
				<image src="@/static/img/healthStatus/depressedOn@2x.png" v-if="aindex == 5 && currentIndex == 5"></image>
				<image src="@/static/img/healthStatus/depressed@2x.png" v-else-if="aindex == 5"></image>
				<image src="@/static/img/healthStatus/medicalOn@2x.png" v-if="aindex == 6 && currentIndex == 6"></image>
				<image src="@/static/img/healthStatus/medical@2x.png" v-else-if="aindex == 6"></image>
				<view :class="aindex == currentIndex ? 'checked' : ''">{{aitem}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				classifcationArr:['生活方式','体检指标','心理健康','健康素养','焦虑状态','抑郁状态','中医体质'],
				currentIndex:0,
				pageIndex: 1,
				pageSize: 10,
				allData: [],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' // 删除按钮背景  红的
					}
				}],
				imgArr:[
					'@/static/img/healthStatus/life@2x.png','@/static/img/healthStatus/examination@2x.png'
				],
				bulletFrame:false, //自定义弹框
				nextPage: 1,
				pageDown: false,
				delStatus: '',
				editStatus: ''
			}
		},
		onLoad(options){
			if(options.current){
				this.currentIndex = options.current
				this.tabClick(Number(options.current))
			}else{
				this.getList(0,{pageIndex:this.pageIndex,pageSize:this.pageSize,upload:1})
			}
			localStorage.removeItem('conversionScore');
			localStorage.removeItem('rapidScreen');
			localStorage.removeItem('smellDetails');
			localStorage.removeItem('appUserTopicsEntities1');
		},
		onReachBottom() {
			if(this.pageDown) {
				return		
			}
			this.nextPage = this.nextPage + 1;
			this.getList(Number(this.currentIndex),{pageIndex:this.nextPage,pageSize:this.pageSize,upload:Number(this.currentIndex+1)})
				
		},
		methods:{
			//下拉框点击切换
			navigationClick(e) {
				this.currentIndex = e;
				this.bulletFrame = false;
				this.allData = [];
				this.nextPage = 1;
				this.getList(e,{pageIndex:this.pageIndex,pageSize:this.pageSize,upload:Number(e+1)})
			},
			//点击切换
			tabClick(e) {
				this.nextPage = 1;
				this.currentIndex = e;	
				this.allData = [];
				this.getList(e,{pageIndex:this.pageIndex,pageSize:this.pageSize,upload:Number(e+1)})
			},
			//跳现状评估列表
			addQuestion() {
				uni.navigateTo({
					url:'/pages/healthStatus/navigatorBar'
				})
			},
			//修改状态
			creat(e) {
				if(this.currentIndex == 1) {
					this.$api.HealthExaminationReportStatus(e.id,2).then((res) => {
						if(res.data.returnCode == 200) {
							this.editStatus = 1;
							this.pageDown = false;
							this.nextPage = 1;
							this.getList(this.currentIndex,{pageIndex:this.pageIndex,pageSize:this.pageSize,upload:Number(this.currentIndex+1)})
						}
					})
				}else {
					this.$api.psychologyQuestionStatus(e.id,2).then((res) => {
						if(res.data.returnCode == 200) {
							this.editStatus = 1;
							this.pageDown = false;
							this.nextPage = 1;
							this.getList(this.currentIndex,{pageIndex:this.pageIndex,pageSize:this.pageSize,upload:Number(this.currentIndex+1)})
						}
					})
				}
				
			},
			//列表
			getList(e,data) {	
				uni.showLoading({
					title: '加载中'
				});
				if(e == 1) {
					this.$api.HealthExaminationReportList(data).then((res) => {
						var data = res.data.result && res.data.result.elements;
						if(this.delStatus == 1 || this.editStatus == 1) {
							this.allData = [];
							this.allData = data;
							this.delStatus = '';
							this.editStatus = '';
						}else {
							this.allData = this.allData ? this.allData.concat(data) : data;
						}					
						if(this.allData.length >= res.data.result.totalCount) {
							this.pageDown = true;
							return
						}else {
							this.pageDown = false
						}
						uni.hideLoading();
					})
				}else {
					this.$api.psychologyQuestionList(data).then((res) =>{
						var data = res.data.result && res.data.result.elements;
						if(this.delStatus == 1 || this.editStatus == 1) {
							this.allData = [];
							this.allData = data;
							this.delStatus = '';
							this.editStatus = '';
						}else {
							this.allData = this.allData ? this.allData.concat(data) : data;
						}					
						if(this.allData.length >= res.data.result.totalCount) {
							this.pageDown = true;
							return
						}else {
							this.pageDown = false
						}
						uni.hideLoading();
					})
				}
				
				
			},
			//删除
			bindClick(e) {
				const _this = this;
				if(this.currentIndex == 1) {
					_this.$api.HealthExaminationReportDel(e.id) .then((res) => {
						if(res.data.returnCode == 200) {
							_this.pageDown = false;
							_this.delStatus = 1;
							_this.nextPage = 1;
							_this.getList(_this.currentIndex,{pageIndex:_this.pageIndex,pageSize:_this.pageSize,upload:Number(_this.currentIndex+1)})
						}
					})
				}else {
					_this.$api.psychologyQuestionDel(e.id).then((res) => {
						if(res.data.returnCode == 200) {
							_this.pageDown = false;
							_this.delStatus = 1;
							_this.nextPage = 1;
							_this.getList(_this.currentIndex,{pageIndex:_this.pageIndex,pageSize:_this.pageSize,upload:Number(_this.currentIndex+1)})
						}
					})
				} 
				
			},
			// 问卷详情
			detail(item){
				if(item.status == 4 ){
					// 编辑
					if(this.currentIndex == 2){
						uni.navigateTo({url:`/pages/healthStatus/mental/createMental?id=${item.id}`})
					}else if(this.currentIndex == 3) {
						uni.navigateTo({url:`/pages/healthStatus/accomplishment/index?id=${item.id}`})
					}else if(this.currentIndex == 0) {
						uni.navigateTo({url:`/pages/healthStatus/lifeStyle/index?id=${item.id}`})
					}else if(this.currentIndex == 4) {
						uni.navigateTo({url:`/pages/healthStatus/anxious/create?id=${item.id}`})
					}else if(this.currentIndex == 5) {
						uni.navigateTo({url:`/pages/healthStatus/depressed/create?id=${item.id}`})
					}else if(this.currentIndex == 1) {
						uni.navigateTo({url:`/pages/healthStatus/examined/index?id=${item.id}`})
					}else if(this.currentIndex == 6) {
						uni.navigateTo({url:`/pages/healthStatus/chineseMedicine/index?id=${item.id}`})
					}
				}else if(item.status == 2) {
					//查看
					if(this.currentIndex == 2){
						uni.navigateTo({url:`/pages/healthStatus/mental/createMental?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 3) {
						uni.navigateTo({url:`/pages/healthStatus/accomplishment/index?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 0) {
						uni.navigateTo({url:`/pages/healthStatus/lifeStyle/index?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 4) {
						uni.navigateTo({url:`/pages/healthStatus/anxious/create?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 5) {
						uni.navigateTo({url:`/pages/healthStatus/depressed/create?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 1) {
						uni.navigateTo({url:`/pages/healthStatus/examined/index?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 6) {
						uni.navigateTo({url:`/pages/healthStatus/chineseMedicine/index?id=${item.id}&selected=1`})
					}
				}else if(item.status == 3 ){
					// 已签发-查看详情
					if(this.currentIndex == 2){
						uni.navigateTo({url:`/pages/healthStatus/mental/toView?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 3) {
						uni.navigateTo({url:`/pages/healthStatus/accomplishment/toView?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 0) {
						uni.navigateTo({url:`/pages/healthStatus/lifeStyle/toView?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 4) {
						uni.navigateTo({url:`/pages/healthStatus/anxious/toView?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 5) {
						uni.navigateTo({url:`/pages/healthStatus/depressed/toView?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 1) {
						uni.navigateTo({url:`/pages/healthStatus/examined/toView?id=${item.id}&selected=1`})
					}else if(this.currentIndex == 6) {
						uni.navigateTo({url:`/pages/healthStatus/chineseMedicine/toView?id=${item.id}&selected=1`})
					}
				}
			},
			//查看报告
			check(e) {
				if(e.url) {
					window.location.href = 'http://health.jlm12580.com/web/viewer.html?file=' + e.url
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/healthStatus/navigation.scss';
	/deep/ .uni-swipe_box{
		display: block !important;
	}
	/deep/.uni-swipe_button{
		padding: 0 20rpx;
		margin-left: 10rpx;
	}

</style>
